﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Xml;
using System.Xml.Linq;
using ABC.Domain.Enums;
using ABC.Business.DailyInfo;

namespace ABC.Business.Models
{
    public class ToolbarModel
    {
        private DailyInfoSoapClient DailyInfo;

        public ToolbarModel()
        {
            DailyInfo = new DailyInfoSoapClient();
        }

        public string[] GetCourse()
        {
            if (HttpContext.Current.Cache["course"] != null)
            {
                return (string[])HttpContext.Current.Cache["course"];
            }
            var todayTable = DailyInfo.GetCursOnDate(DateTime.Now).Tables["ValuteCursOnDate"];
            var tommorowTable = DailyInfo.GetCursOnDate(DateTime.Now.AddDays(1)).Tables["ValuteCursOnDate"];
            var courses = new[] { todayTable.Rows[9]["Vcurs"].ToString(), tommorowTable.Rows[9]["Vcurs"].ToString(), todayTable.Rows[10]["Vcurs"].ToString(), tommorowTable.Rows[10]["Vcurs"].ToString() };
            HttpContext.Current.Cache.Add("course", courses, null, DateTime.Now.AddHours(30), Cache.NoSlidingExpiration,
                                          CacheItemPriority.Normal, null);
            return courses;

        }

    }
}
